// leaderPerson/pages/facePay/facePay.js
var common = require("../../../common/common.js").common;

const app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        capsule: {},
        pay_price: ""
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        let res = wx.getMenuButtonBoundingClientRect();
        console.log(res);
        this.setData({
            capsule: res
        });
        console.log(this.capsule);
        this.getBase();
        this.getQr();
    },
    setPrice() {
        let that = this;
        wx.showModal({
            title: "设置金额",
            content: "",
            editable: true,
            success: function(res) {
                if (res.confirm) {
                    if (!/^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$/.test(Number(res.content))) {
                        wx.showModal({
                            title: "提示",
                            content: "请输入正确的金额，金额需大于0且最多保留两位小数！"
                        });
                        return;
                    }
                    if (Number(res.content) < .01) {
                        wx.showModal({
                            title: "提示",
                            content: "金额不能低于0.01元！"
                        });
                        return;
                    }
                    common.request({
                        endpoint: "Leader/leaderfacepay/leader-qr-code",
                        method: "post",
                        data: {
                            page: "leaderPerson/pages/facePayDetail/facePayDetail",
                            money: res.content
                        },
                        success: function(resc) {
                            if (resc.code == 0) {
                                that.setData({
                                    qr: resc.extra.qr_code,
                                    pay_price: Number(res.content)
                                });
                            } else {
                                wx.showModal({
                                    title: "提示",
                                    content: resc.message
                                });
                            }
                        },
                        fail: function(resc) {
                            wx.showModal({
                                title: "提示",
                                content: resc.message
                            });
                        }
                    });
                }
            }
        });
    },
    goToPay() {
        wx.navigateTo({
            url: "/leaderPerson/pages/facePayDetail/facePayDetail"
        });
    },
    goTorecordList() {
        wx.navigateTo({
            url: "/leaderPerson/pages/facePayRecordList/facePayRecordList"
        });
    },
    getQr() {
        let that = this;
        common.request({
            endpoint: "Leader/leaderfacepay/leader-qr-code",
            method: "post",
            data: {
                page: "leaderPerson/pages/facePayDetail/facePayDetail"
            },
            success: function(res) {
                if (res.code == 0) {
                    that.setData({
                        qr: res.extra.qr_code
                    });
                } else {
                    wx.showToast({
                        title: "提示",
                        content: res.message
                    });
                }
            },
            fail: function(res) {
                wx.showModal({
                    title: "提示",
                    content: res.message
                });
            }
        });
    },
    getBase: function() {
        var that = this;
        common.request({
            endpoint: "set/app_base",
            method: "get",
            data: {},
            success: res => {
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: res.extra.color_main
                });
                that.setData({
                    color_main: res.extra.color_main,
                    color_minor: res.extra.color_minor,
                    on_off_trans_free: res.extra.on_off_trans_free,
                    trans_for_free_barrier: res.extra.trans_for_free_barrier,
                    new_member_audit: res.extra.new_member_audit,
                    userAuditStatus: res.extra.userAuditStatus ? res.extra.userAuditStatus : 2
                });
            }
        });
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {}
});